#ifndef SAVEGRAYPIC_H
#define SAVEGRAYPIC_H

#include <QObject>
#include <QElapsedTimer>
#include <QtEndian>

#include "savebase.h"

/***
 *地面长波红外
 * 320 * 256
 * fps: 100
 * **/

class SaveGroundLongWV : public SaveBase
{
    Q_OBJECT
public:
    explicit SaveGroundLongWV(int width, int height, QObject *parent = nullptr);

    bool saveRawImage(const QByteArray &imageData);

public slots:
    void onWorking(const QString ip, const quint16 port, const QByteArray arr);

    void onInitTimer()override{}     //初始化定时器, 本类不需要该函数

signals:
    // 帧组装完成后发送信号
    void frameCompleted(const QByteArray& imageData, int width, int height);

private:
    struct FrameData {
        QByteArray data;
        int width = 0;
        int height = 0;
    };

    QMap<quint16, FrameData> frameMap; // 帧计数器 -> 帧数据

    bool m_hasHead;

    int m_totalPackets = -1;
    int m_receivedPackets = -1;
    FrameData frame;

    // 帧率统计变量
    QElapsedTimer m_fpsTimer;
    int m_TimeCount = 0;
    double m_currentFps = 0.0;

    int m_width = 0;
    int m_height = 0;
    int m_bytes = 0;
};

#endif // SAVEGRAYPIC_H
